/**
 * @Description 留宿申请的控制层
 * @author 20155870 杨润增
 * @create 2018-05-06 14:11
 **/
package com.campus_information_portal.controller;

import com.campus_information_portal.entity.DorStuTerm;
import com.campus_information_portal.entity.Project;
import com.campus_information_portal.service.DormitoryService;
import com.campus_information_portal.service.ProjectService;
import com.campus_information_portal.util.Message;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.net.UnknownHostException;
import java.util.Date;

/**
 * @className ProjectController
 * @Description 宿舍管理的控制层
 * @author 20155870 杨润增
 * @create 2018-05-06 14:11
 **/
@Controller
@RequestMapping("/project")
@ResponseBody
@CrossOrigin(origins = "*")
public class ProjectController {
    @Autowired
    private ProjectService projectService;


    @RequestMapping(value = "/applyProject",method = RequestMethod.GET)
    public Message apply(@Param("termId")int termId,
                         @Param("stuInfoId")int stuInfoId,
                         @Param("projectName")String projectName,
                         @Param("projectContent")String projectContent,
                         @Param("projectPhonenum")String projectPhonenum,
                         @Param("projectStartDate")Date projectStartDate,
                         @Param("projectEndDate")Date projectEndDate,
                         @Param("projectContactPeople")String projectContactPeople,
                         @Param("projectPlatform")String projectPlatform,
                         @Param("projectState")int projectState
                         ){
        return projectService.addProject(termId,stuInfoId,projectName,projectContent,projectPhonenum,
                projectStartDate,projectEndDate,projectContactPeople,projectPlatform,projectState);
    }

    @RequestMapping(value = "/queryMyProject", method = RequestMethod.GET)
    public Message queryMyProject(@Param("stuNum")int stuNum) {
        return projectService.queryMyProject(stuNum);
    }

    @RequestMapping(value = "/queryAllProject", method = RequestMethod.GET)
    public Message queryAllProject() {
        return projectService.queryAllProject();
    }

    @RequestMapping(value = "/queryProjectByProjectId", method = RequestMethod.GET)
    public Message editMyProject(@Param("projectId")int projectId) {
        return projectService.queryProjectById(projectId);
    }

   @RequestMapping(value = "/updateProject",method = RequestMethod.POST)
    public Message updateProject(@RequestBody Project project) {
        System.out.println(project);
        return projectService.updateAProject(project);
    }

     @RequestMapping(value = "/download",method = RequestMethod.GET)
    public Message refuse(@Param("stuNum") int stuNum,@Param("stuName") String stuName,
                          @Param("stuSex") String stuSex,@Param("academyName") String academyName,
                          @Param("termYear") String termYear,@Param("termNum") String termNum,
                          @Param("startDate") String startDate,@Param("endDate") String endDate,
                          @Param("contact") String contact,@Param("contactPhone") String contactPhone,
                          @Param("platform") String platform,@Param("proName") String proName,
                          @Param("proContent")String proContent) throws UnknownHostException {
        return projectService.download(stuNum,stuName,stuSex,academyName,
                 termYear,termNum,startDate,endDate,
                contact,contactPhone,platform,proName,
                proContent);
    }

    @RequestMapping(value = "/updateProjectState",method = RequestMethod.GET)
    public Message updateProject(@Param("projectId") int projectId,@Param("projectState") int projectState) {
        return projectService.updateProjectstate(projectId,projectState);
    }



}
